export const setLocalPlayletInfo = (info: { [key: string]: any }) => {
  const localPlayletInfo = getLocalPlayletInfo();
  if (localPlayletInfo) {
    localStorage.setItem(
      "localPlayletInfo",
      JSON.stringify(Object.assign(localPlayletInfo, info)),
    );
  } else {
    localStorage.setItem("localPlayletInfo", JSON.stringify(info));
  }
};

export const getLocalPlayletInfo = () => {
  const res = localStorage.getItem("localPlayletInfo");

  if (res) {
    try {
      return JSON.parse(res);
    } catch (e) {
      return null;
    }
  }
  return null;
};

/**
 * 获取封面图
 * @param vid 视频ID
 * @param index 第几集
 */
export function getCoverImg(vid: string, index: string | number) {
  return `https://d2xy5ri6f1d6yp.cloudfront.net/cover/sliceCover/${vid}/${index}.jpg`;
}
